﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace Mvc.XForms.UI.Settings {
	public class GridSettings<T> {
		public IGrid<T> Grid;

		public GridSettings(IGrid<T> grid) {
			Grid = grid;
		}

		public void Body(Action<T> rowTemplate) {
			Grid.BodyAction = rowTemplate;
			Grid.Render();
		}

		public GridSettings<T> Head(Action<IGridHead<T>> head) {
			Grid.HeadAction = head;
			return this;
		}

		public GridSettings<T> Pager() {;
			return Pager(PagerPosition.TopAndBottom, null);
		}

		public GridSettings<T> Pager(PagerPosition pagerPosition) {

			return Pager(pagerPosition, null);
		}

		public GridSettings<T> Pager(PagerPosition pagerPosition, IPagerFormatter pagerFormatter) {
			Grid.IsPaged = true;
			Grid.PagerPosition = pagerPosition;
			Grid.PagerFormatter = pagerFormatter ?? Grid.PagerFormatter;
			return this;
		}

		public GridSettings<T> NoResultHtml(Action noResultHtml) {
			Grid.NoResultHtml = noResultHtml;
			return this;
		}
	}
}
